<template>
  <div>
    <el-table
      v-loading="listLoading"
      :key="tableKey"
      :data="list"
      element-loading-text="给我一点时间"
      border
      fit
      highlight-current-row
      style="width: 100%">
      <el-table-column width="120" align="center" label="消防设施图像">
        <template slot-scope="scope">
          <embed :src="scope.row.assetimageurl" style="height:auto;width:100%;">
        </template>
      </el-table-column>
      <el-table-column width="200" align="center" label="消防设施名称">
        <template slot-scope="scope">
          <span>{{ scope.row.assetname }}</span>
        </template>
      </el-table-column>
      <el-table-column width="130" align="center" label="传感器ID">
        <template slot-scope="scope">
          <span>{{ scope.row.deviceid }}</span>
        </template>
      </el-table-column>
      <el-table-column width="130" align="center" label="传感器名称">
        <template slot-scope="scope">
          <span>{{ scope.row.devicename }}</span>
        </template>
      </el-table-column>
      <el-table-column width="130" align="center" label="传感器图片">
        <template slot-scope="scope">
          <!-- <span>{{ scope.row.deviceimageurl }}</span> -->
          <embed :src="scope.row.deviceimageurl" style="height:auto;width:100%;">
        </template>
      </el-table-column>
      <el-table-column width="130" align="center" label="传感器位置">
        <template slot-scope="scope">
          <span>{{ scope.row.location }}</span>
        </template>
      </el-table-column>

      <el-table-column :label="$t('table.actions')" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button type="primary" size="mini" @click="handleMeasure(scope.row)">{{ $t('table.measurements') }}</el-button>
        </template>
      </el-table-column>

    </el-table>

    <div class="pagination-container">
      <el-pagination
        :current-page.sync="listQuery.page"
        :page-sizes="[10,20,30, 50]"
        :page-size="listQuery.pagesize"
        :total="total"
        background
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"/>
    </div>
  </div>
</template>

<script>

import { assignmentList } from '@/api/fire/asset/asset'
import waves from '@/directive/waves' // 水波纹指令

export default {
  name: 'AssignmentList',
  directives: {
    waves
  },
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: 'success',
        draft: 'info',
        deleted: 'danger'
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      tableKey: 0,
      list: null,
      total: null,
      listLoading: true,
      listQuery: {
        page: 1,
        pagesize: 10,
        assetname: '',
        siteid: this.$store.state.asset.siteid
      },
      showReviewer: false,
      dialogFormVisible: false,
      dialogStatus: '',
      textMap: {
        update: '编辑',
        create: '创建',
        delete: '删除',
        details: '详情',
        binding: '绑定'
      },
      dialogPvVisible: false,
      dialogFormRolesVisible: false,
      btn_query: false,
      btn_add: false,
      btn_edit: false,
      btn_delete: false
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      this.listLoading = true
      assignmentList(this.listQuery).then(response => {
        this.list = response.data.context.assignedlists
        this.total = response.data.context.total
        this.listLoading = false
      })
    },
    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },
    handleSizeChange(val) {
      this.listQuery.pagesize = val
      this.getList()
    },
    handleCurrentChange(val) {
      this.listQuery.page = val
      this.getList()
    },
    handleMeasure(row) {
      this.$router.push({
        path: '/asset/measure',
        name: 'measure',
        params: {
          'assetid': row.assetid,
          'assignmentToken': row.assignmentToken
        }
      })
    },
    handleModifyStatus(row, status) {
      this.$message({
        message: '操作成功',
        type: 'success'
      })
      row.status = status
    },
    handleUnbind(row) {
      this.$confirm('此操作将解除绑定, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        // deleteSupervisor(row.supervisorid).then(response => {
        //   if (response.data.status === '0') {
        //     this.getList()
        //     this.$notify({
        //       title: '成功',
        //       message: response.data.msg,
        //       type: 'success',
        //       duration: 2000
        //     })
        //   } else {
        //     this.$notify.error({
        //       title: '失败',
        //       message: response.data.msg,
        //       duration: 2000
        //     })
        //   }
        // })
      })
    }
  }
}
</script>

